package com.ruoyi.eqmonitor.version.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.version.domain.BizAppVersion;
import com.ruoyi.eqmonitor.version.service.IBizAppVersionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * App版本更新
 * @author breeze
 * @date 2023-06-21
 */
@RestController
@RequestMapping("/version")
public class BizAppVersionController extends BaseController{
    
    @Autowired
    private IBizAppVersionService bizAppVersionService;

    /**
     * 多条件查询App版本列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(BizAppVersion bizAppVersion){
        startPage();
        List<BizAppVersion> list = bizAppVersionService.selectBizAppVersionList(bizAppVersion);
        return getDataTable(list);
    }

    /**
     * 根据id获取单条App版本
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(bizAppVersionService.selectBizAppVersionById(id));
    }
    
    /**
     * 获取最新版App数据
     */
    @GetMapping(value = "/latest")
    public AjaxResult getLatest(){
        return AjaxResult.success(bizAppVersionService.selectLatestBizAppVersion());
    }
    
    /**
     * 新增单条App数据
     */
    @Log(title = "App版本更新", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizAppVersion bizAppVersion){
    	bizAppVersion.setCreateTime(new Date());
    	bizAppVersion.setCreateBy(SecurityUtils.getUsername());
        return toAjax(bizAppVersionService.save(bizAppVersion));
    }

    /**
     * 修改单条App数据
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BizAppVersion bizAppVersion){
    	bizAppVersion.setUpdateTime(new Date());
    	bizAppVersion.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(bizAppVersionService.updateById(bizAppVersion));
    }

    /**
     * 批量删除App数据
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "App版本更新", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(bizAppVersionService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出App版本更新列表
     */
    @Log(title = "App版本更新", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizAppVersion bizAppVersion){
        List<BizAppVersion> list = bizAppVersionService.selectBizAppVersionList(bizAppVersion);
        ExcelUtil<BizAppVersion> util = new ExcelUtil<BizAppVersion>(BizAppVersion.class);
        util.exportExcel(response, list, "App版本更新数据");
    }
    
}
